package com.gitee.l0km.codegen.generic;

import org.apache.commons.cli.Options;

import com.gitee.l0km.codegen.base.generator.Generator;
import com.gitee.l0km.codegen.base.generator.GeneratorConfiguration;
import com.gitee.l0km.com4j.cli.Context;

public class GenericGenerator extends Generator {

	private final GenericInterfaceOptions options = GenericInterfaceOptions.getInstance();
	private final GenericInferfaceConfiguration config = new GenericInferfaceConfiguration();

	public GenericGenerator() {
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public Context createEngineContext() {
		GenericInterface newSourceInfo = new GenericInterface(config.getInterfaceClass(), config.getRefClass(), config.getShellInterface());
		if (!newSourceInfo.compile()){
			System.exit(1);
		}
		Context context = super.createEngineContext();
		context.setProperty(SOURCE_INFO, newSourceInfo);
		return context;
	}

	@Override
	protected Options getOptions() {
		return options.getOptions();
	}

	protected GeneratorConfiguration getGeneratorConfiguration() {
		return this.config;
	}

	public static void main(String[] args) {
		new GenericGenerator().parseCommandLine(args).initEngine().generate();
	}

}
